#define _CRT_SECURE_NO_WARNINGS 1


#include<map>
#include<vector>
#include<iostream>

using namespace std;

int totalFruit(vector<int>& fruits)
{
    map<int, int> hash;
    int size = fruits.size();
    int left = 0, right = 0, Max = 0;
    while (right < size)
    {
        hash[fruits[right]]++;
        while (hash.size() > 2)
        {
            Max = max(Max, right - left);
            hash[fruits[left]]--;
            if (hash[fruits[left]] == 0)
            {
                hash.erase(fruits[left]);
            }
            left++;
        }
        right++;
    }
    Max = max(Max, right - left);
    return Max;
}

//int main()
//{
//    vector<int> v = { 3,3,3,1,2,1,1,2,3,3,4 };
//    cout << totalFruit(v) << endl;
//
//	return 0;
//}